def solution(expression):
    def calculate(s):
        num_stack = []  # 数字栈
        op_stack = []  # 运算符栈
        num = 0
        i = 0

        while i < len(s):
            char = s[i]

            if char.isdigit():  # 如果字符是数字
                num = int(char)
                # 处理优先级
                while op_stack and op_stack[-1] in ('*', '/'):
                    last_op = op_stack.pop()
                    last_num = num_stack.pop()
                    if last_op == '*':
                        num = last_num * num
                    elif last_op == '/':
                        num = last_num // num

                num_stack.append(num)  # 将当前数字入栈
                num = 0  # 重置数字

            elif char in '+-*/':  # 处理运算符
                op_stack.append(char)  # 将当前运算符入栈

            elif char == '(':
                op_stack.append(char)  # 将左括号入栈

            elif char == ')':
                while op_stack and op_stack[-1] != '(':
                    eval_stack(num_stack, op_stack)
                op_stack.pop()  # 移除左括号

            i += 1

        # 处理最后一个数字
        if num > 0:
            num_stack.append(num)

        # 处理剩余的运算符
        while op_stack:
            eval_stack(num_stack, op_stack)

        return num_stack[0]  # 返回最终结果

    def eval_stack(num_stack, op_stack):
        """计算栈中的所有数字并返回总和。"""
        num2 = num_stack.pop()
        num1 = num_stack.pop()
        op = op_stack.pop()
        if op == '+':
            num_stack.append(num1 + num2)
        elif op == '-':
            num_stack.append(num1 - num2)
        elif op == '*':
            num_stack.append(num1 * num2)
        elif op == '/':
            num_stack.append(num1 // num2)  # 整数除法

    return calculate(expression)


if __name__ == "__main__":
    # 添加测试用例
    print(solution("1+1") == 2)  # 应输出: True
    print(solution("3+4*5/(3+2)") == 7)  # 应输出: True
    print(solution("4+2*5-2/1") == 12)  # 应输出: True
    print(solution("(1+(4+5+2)-3)+(6+8)") == 23)  # 应输出: True
